import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/customwidget/container_widget/page/ItemPage.dart';
import 'package:flutter_app/util/ToastUtil.dart';

/// AppBar({
/// Key key,
/// this.leading, //导航栏最左侧Widget，常见为抽屉菜单按钮或返回按钮。
///  this.automaticallyImplyLeading = true, //如果leading为null，是否自动实现默认的leading按钮
///  this.title,// 页面标题
///  this.actions, // 导航栏右侧菜单
///  this.bottom, // 导航栏底部菜单，通常为Tab按钮组
/// this.elevation = 4.0, // 导航栏阴影
/// this.centerTitle, //标题是否居中
/// this.backgroundColor,
/// ...   //其它属性见源码注释
// })
class ScaffoldTabBarWidget extends StatefulWidget {
  ScaffoldTabBarWidget({
    Key? key,
    @required this.text,
  }) : super(key: key);

  final String? text;

  @override
  State<StatefulWidget> createState() {
    return new _ScaffoldState(text ?? "");
  }
}

class _ScaffoldState extends State<ScaffoldTabBarWidget> {
  List<Widget> _pages = [
    ItemPage("Home"),
    ItemPage("Business"),
    ItemPage("School"),
  ];

  String? title; //标题
  _ScaffoldState(String text) {
    title = text;
  }

  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        //导航栏
        title: Text(title??""),
        actions: [
          //导航栏右侧菜单
          IconButton(
              icon: Icon(Icons.share),
              onPressed: () {
                ToastUtil.toastShort("点击分享");
              })
        ],
      ),
      // drawer: Drawer(), //抽屉
      //   CupertinoTabBar ios
      bottomNavigationBar: BottomNavigationBar(
        //底部导航
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: "Home"),
          BottomNavigationBarItem(
              icon: Icon(Icons.business), label: "Business"),
          BottomNavigationBarItem(icon: Icon(Icons.school), label: "School")
        ],
        currentIndex: _selectedIndex,
        selectedFontSize: 15,
        unselectedFontSize: 13,
        selectedItemColor: Colors.black,
        unselectedItemColor: Colors.grey,
        onTap: _onItemTapped, //点击
      ),
      body: _pages[_selectedIndex],
    );
  }

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }
}
